﻿<?php
require('configs/include.php');

class c_updateEnd extends super_controller {

    public function finalizarKernel() {
        if ($_SESSION['user']['type'] == "lider") {
            $kernel = new kernel($this->post);
            if (is_empty($kernel->get('id'))) {
                throw_exception("Debe seleccionar una versión de kernel");
            } else {
                $this->orm->connect();
                $this->orm->update_data("by_id", $kernel);
                $this->orm->close();

                $this->type_warning = "success";
                $this->msg_warning = "Se finalizó correctamente el kernel";
                $this->img_warning = "correct.png";
                $this->engine->assign('img_warning', $this->img_warning);
                $this->temp_aux = 'message.tpl';

                $this->engine->assign('type_warning', $this->type_warning);
                $this->engine->assign('msg_warning', $this->msg_warning);
            }
        }
    }

    public function display() {
        if ($_SESSION['user']['type'] == "lider") {
            
            $kernel = new kernel($this->post); //por mi
            $cod['modulo']['kernel'] = $kernel->get('id');
            $options['modulo']['lvl2'] = "all";
            $options['kernel']['lvl2'] = "by_state";
            
            
            //para tratar de comprimir modulo y programa////////////////////////
            $components['modulo']['kernel'] = array("k_m");
           // $components['programa']['modulo'] = array("m_p");
            ////////////////////////////////////////////////////////////////////
            $this->orm->connect();
            $this->orm->read_data(array("kernel","modulo"), $options, $cod);
            $kernels = $this->orm->get_objects("kernel", $components);
            
            print_r2($kernels);
            $this->orm->close();
            $this->engine->assign('kernels', $kernels);
            $varAux = $this->gvar['n_index'] . " -> " . $this->gvar['n_request'];
            $this->engine->assign('ubicationPath', $varAux);
            $this->engine->display('header.tpl');
            $this->engine->display('updateEnd.tpl');
            $this->engine->display('footer.tpl');
        } else {
            $this->engine->display('header.tpl');
            $this->engine->display('sinPermisos.tpl');
            $this->engine->display('footer.tpl');
        }
    }

    public function run() {
        try {
            if (isset($this->get->option)) {
                $this->{$this->get->option}();
            }
        } catch (Exception $e) {
            $this->error = 1;
            $this->msg_warning = $e->getMessage();
            $this->img_warning = "incorrect.png";
            $this->engine->assign('type_warning', $this->type_warning);
            $this->engine->assign('msg_warning', $this->msg_warning);
            $this->engine->assign('img_warning', $this->img_warning);
            $this->temp_aux = 'message.tpl';
        }
        $this->display();
    }

}

$call = new c_updateEnd();
$call->run();
?>